package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.Log;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.core.page.TableDataInfo;
import com.lakeworks.common.enums.BusinessType;
import com.lakeworks.domain.SysWechatUser;
import com.lakeworks.service.ISysWechatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 微信用户Controller
 *
 * @author lake
 * @date 2023-02-20
 */
@RestController
@RequestMapping("/wechat/user")
public class SysWechatUserController extends BaseController {
    @Autowired
    private ISysWechatUserService sysWechatUserService;

    /**
     * 查询微信用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWechatUser sysWechatUser) {
        startPage();
        List<SysWechatUser> list = sysWechatUserService.selectSysWechatUserList(sysWechatUser);
        return getDataTable(list);
    }

//    /**
//     * 导出微信用户列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:user:export')")
//    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, SysWechatUser sysWechatUser)
//    {
//        List<SysWechatUser> list = sysWechatUserService.selectSysWechatUserList(sysWechatUser);
//        ExcelUtil<SysWechatUser> util = new ExcelUtil<SysWechatUser>(SysWechatUser.class);
//        util.exportExcel(response, list, "微信用户数据");
//    }

    /**
     * 获取微信用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysWechatUserService.selectSysWechatUserById(id));
    }

    /**
     * 新增微信用户
     */
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWechatUser sysWechatUser) {
        return toAjax(sysWechatUserService.insertSysWechatUser(sysWechatUser));
    }

    /**
     * 修改微信用户
     */
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWechatUser sysWechatUser) {
        return toAjax(sysWechatUserService.updateSysWechatUser(sysWechatUser));
    }

    /**
     * 删除微信用户
     */
    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysWechatUserService.deleteSysWechatUserByIds(ids));
    }
}
